/*
 * CvApplication.h
 *
 *  Created on: 2018年3月20日
 *      Author: zhengboyuan
 */

#ifndef CVAPPLICATION_H_
#define CVAPPLICATION_H_

#include "BasicType.h"
#include "CvUtil.h"

#include "DirVideoSource.h"

void trace(const char* fmt, ...);



class CvApplication
{
public:
	static void TrackbarCallback(int pos, void* userdata);
	static void MouseCallback(int event, int x, int y, int flags, void* param);

	typedef std::vector<cv::Point>	Points;
	typedef std::vector< Points >	Contours;

public:
	CvApplication();
	virtual ~CvApplication();

	void run();

public:
	void onTrack();
	void onMouse(int event, int x, int y, int flags);

protected:
	void setup();
	void teardown();

	void process();

	cv::Mat process(cv::Mat& src);

	void processNext();

	cv::Mat processEdge(cv::Mat& src);

	cv::Mat processColor(cv::Mat& src);

	cv::Mat processHeadCounter(cv::Mat& src);

	cv::Mat processLine(cv::Mat& src);

	cv::Mat processErode(cv::Mat& src);


	cv::Mat processForeground(cv::Mat& src);

	cv::Mat makeForeground(cv::Mat& src);
	cv::Mat makeForeground(cv::Mat& src, double lowThresh, double highThresh, int minRadius);
	cv::Mat makeContourRectMat(cv::Mat& binMat, int minRadius);

	cv::Mat makeContours(cv::Mat& binMat, int minArc, double minArea, Contours& contours);

protected:
	cv::Mat	m_originMat;
	cv::Mat	m_srcMat;
	cv::Mat	m_outMat;

	cv::NamedWindow m_srcWindow;
	cv::NamedWindow	m_outWindow;
	cv::NamedWindow	m_watchWindow;

	cv::Trackbar	m_hTrack;
	cv::Trackbar	m_sTrack;
	cv::Trackbar	m_vTrack;

	cv::Trackbar	m_hdTrack;
	cv::Trackbar	m_sdTrack;
	cv::Trackbar	m_vdTrack;

	cv::Trackbar	m_arcTrack;
	cv::Trackbar	m_areaTrack;
	cv::Trackbar	m_radiusTrack;

	DirVideoSource	m_videoSource;

};

#endif /* CVAPPLICATION_H_ */
